//
//  MovementsContentCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/1.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "MovementsContentCell.h"
#import "LabCell.h"
@interface MovementsContentCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic ,strong) UICollectionView *collectionView;
@end
@implementation MovementsContentCell{
    MovementsModel   *movementsModel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor=DEFAULTBGCOLOR;
        WS(weakSelf);
        [self.contentView addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(weakSelf.contentView).with.offset(13);
            make.right.equalTo(weakSelf.contentView).with.offset(-13);
            make.height.mas_offset(@(46*2));
        }];
        UIButton *btnMore=[[UIButton alloc]init];
        [btnMore setTitleColor:DEFAULTTEXTGDARKRAYCOLOR forState:UIControlStateNormal];
        [btnMore setTitle:@"查看更多" forState:UIControlStateNormal];
        [btnMore.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:btnMore];
        [btnMore mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.collectionView.mas_bottom).
            with.offset(-15);
            make.left.right.bottom.equalTo(weakSelf.contentView);
        }];
    }
    return self;
}

- (void)setModel:(MovementsModel *)model{
    movementsModel=model;
}

#pragma mark - collectionView代理函数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return movementsModel.version.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LabCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"LabCell" forIndexPath:indexPath];
    [cell setBGColor:[UIColor colorWithHexString:@"#dddddd"] andTitle:movementsModel.version[indexPath.row] andCornerRadius:4.0];
    return cell;
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        [layout setItemSize:CGSizeMake((SCREEN_WIDTH-26*3)/3.0, 30)];
        [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
        layout.minimumInteritemSpacing = 13.0;
        layout.minimumLineSpacing = 13.0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor=DEFAULTBGCOLOR;
        _collectionView.showsVerticalScrollIndicator=NO;
        [_collectionView registerClass:[LabCell class] forCellWithReuseIdentifier:@"LabCell"];
        _collectionView.userInteractionEnabled=YES;
        
    }
    return _collectionView;
}

@end
